import java.util.ArrayList;
interface Observer {
    void update(float temp, float humidity, float cleanness);
}
interface Subject {
    void registerObserver(Observer o);
    void removeObserver(Observer o);
    void notifyObservers();
}
class Environment implements Subject {
    private float temperature,humidity,cleanness;
//    观察者列表
    private ArrayList<Observer> observers;
    public Environment() {
        observers = new ArrayList<Observer>();
    }
    public void registerObserver(Observer o) {
        observers.add(o);
    }
    public void removeObserver(Observer o) {
        int i = observers.indexOf(o);
        if (i >= 0) {
            observers.remove(i);
        }
    }
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update(temperature, humidity, cleanness);
        }
    }
//    当从气象站得到更新观测值时，通知观察者
    public void measurementsChanged() {
        notifyObservers();
    }
//    当气象测量更新时，我们用此方法通知观察者。
    public void setMeasurements(float temperature, float humidity, float cleanness) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.cleanness = cleanness;
        measurementsChanged();
    }
}
class CurrentConditionsDisplay implements Observer {
    private float temperature, humidity, cleanness;
    private Subject environment;
    public CurrentConditionsDisplay(Subject environment) {
        this.environment = environment;
        environment.registerObserver(this);
    }
    public void update(float temperature, float humidity, float cleanness) {
        this.temperature = temperature;
        this.humidity = humidity;
        this.cleanness = cleanness;
        display();
    }
    public void display() {
        System.out.println("Current conditions: " + temperature + "F degrees and " + humidity + "% humidity and " + cleanness + "% cleanness");
    }
}
public class Test {
    public static void main(String[] args) {
        Environment weatherData = new Environment();
        CurrentConditionsDisplay currentDisplay = new CurrentConditionsDisplay(weatherData);
        weatherData.setMeasurements(80, 65, 90);
    }
}
